﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:local="clr-namespace:OMANE.Modules.Indicateurs"
    xmlns:selectors="clr-namespace:OMANE.Modules.Indicateurs.Views.Selectors"
	xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:ig="http://schemas.infragistics.com/xaml"    
	mc:Ignorable="d"
	x:Class="Views.ViewDetailEdit"
	d:DesignWidth="640" d:DesignHeight="480">

    <!--<UserControl.DataContext>
		<local:VMEditableObject>
			<local:VMEditableObject.PropertyGroups>
				<local:VMEditablePropertyGroup Name="YOU"/>
			</local:VMEditableObject.PropertyGroups>
		</local:VMEditableObject>
	</UserControl.DataContext>-->

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MinWidth="125"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MinHeight="30" />
            <RowDefinition/>
        </Grid.RowDefinitions>
        <GridSplitter HorizontalAlignment="Stretch" Grid.Column="1" Grid.RowSpan="2" />
        <ListBox Grid.Row="1" ItemsSource="{Binding PropertyGroups}" IsSynchronizedWithCurrentItem="True">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid MinHeight="35">
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="10,0,0,0" FontSize="16" FontWeight="Bold" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <ListBox Grid.Column="2"  Grid.Row="1" ItemsSource="{Binding PropertyGroups/Properties}" IsSynchronizedWithCurrentItem="True">
            <ListBox.Resources>
                <DataTemplate DataType="sys:String">
                    <TextBox />
                </DataTemplate>
                <DataTemplate DataType="sys:Boolean">
                    <TextBox />
                </DataTemplate>
                <DataTemplate DataType="sys:Double">
                    <CheckBox />
                </DataTemplate>
                <DataTemplate DataType="sys:Enum">
                    <ComboBox />
                </DataTemplate>
            </ListBox.Resources>
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Expander IsExpanded="{Binding Path=Extras.IsExpanded}" HorizontalContentAlignment="Stretch">
                                    <Expander.Header>
                                        <!--<Grid HorizontalAlignment="Stretch">-->
                                        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Margin="10,0,0,0" >
                                            <TextBlock Text="{Binding Name}" Margin="0,0,15,0" VerticalAlignment="Center" />
                                            <TextBlock Text="( " VerticalAlignment="Center" />
                                            <TextBlock Text="{Binding Type.Namespace}" VerticalAlignment="Center" />
                                            <TextBlock Text="." VerticalAlignment="Center" />
                                            <TextBlock Text="{Binding Type.Name}" VerticalAlignment="Center" />
                                            <TextBlock Text=" )" VerticalAlignment="Center" />
                                        </StackPanel>

                                        <!--<Button Content="-o-o>" FontWeight="Bold" FontSize="16" HorizontalAlignment="Right">
                                               
                                            </Button>-->
                                        <!--</Grid>-->
                                    </Expander.Header>
                                    <ContentControl MinHeight="30" Content="{Binding}" Margin="0,2,0,0" BorderBrush="Black" BorderThickness="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" >
                                        <ContentControl.Resources>
                                            <local:BrushColorConverter x:Key="BrushColorConverter" />
                                            <DataTemplate x:Key="string">
                                                <TextBox  Text="{Binding Path=Value}" />
                                            </DataTemplate>
                                            <DataTemplate x:Key="boolean">
                                                <CheckBox IsChecked="{Binding Path=Value}" />
                                            </DataTemplate>
                                            <DataTemplate x:Key="double">
                                                <TextBox Text="{Binding Path=Value}"/>
                                            </DataTemplate>
                                            <DataTemplate x:Key="enum" >
                                                <ComboBox ItemsSource="{Binding Extras.EnumValues}" SelectedItem="{Binding Path=Value}"/>
                                            </DataTemplate>
                                            <DataTemplate x:Key="color" >
                                                <Grid>
                                                    <ig:XamColorPicker SelectedColor="{Binding Path=Value, Mode=TwoWay}" />
                                                </Grid>
                                            </DataTemplate>
                                            <DataTemplate x:Key="brush">
                                                <Grid>
                                                    <ig:XamColorPicker SelectedColor="{Binding Path=Value, Mode=TwoWay, Converter={StaticResource BrushColorConverter}}" />
                                                </Grid>
                                            </DataTemplate>
                                            <DataTemplate x:Key="indicatorkey" >
                                                <Grid >
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition />
                                                    </Grid.RowDefinitions>
                                                    <ComboBox ItemsSource="{Binding Source={x:Static Member=local:Model.Instance}, Path=Indicators}" SelectedItem="{Binding Path=Value}"/>
                                                    <DataGrid Grid.Row="1" ItemsSource="{Binding Extensions}">
                                                        <DataGrid.Columns>
                                                            <DataGridTextColumn Header="Parametre" Binding="{Binding Path=Name}"/>
                                                            <DataGridTextColumn Header="Valeur" Binding="{Binding Path=Value}" />
                                                        </DataGrid.Columns>
                                                    </DataGrid>
                                                </Grid>
                                            </DataTemplate>
                                            <DataTemplate x:Key="fontfamily" >
                                                <Grid>
                                                    <ComboBox ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}" SelectedItem="{Binding Path=Value}">
                                                        <ComboBox.ItemTemplate>
                                                            <DataTemplate >
                                                                <TextBlock Text="{Binding Source}" FontFamily="{Binding}" />
                                                            </DataTemplate>
                                                        </ComboBox.ItemTemplate>
                                                    </ComboBox>
                                                </Grid>
                                            </DataTemplate>
                                            <DataTemplate x:Key="police">
                                                <Grid DataContext="{Binding Path=Value}">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition />
                                                        <RowDefinition Height="Auto" />
                                                    </Grid.RowDefinitions>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition />
                                                    </Grid.ColumnDefinitions>
                                                    <ComboBox Grid.ColumnSpan="3"  ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}" SelectedItem="{Binding Path=Font}">
                                                        <ComboBox.ItemTemplate>
                                                            <DataTemplate >
                                                                <TextBlock Text="{Binding Source}" FontFamily="{Binding}" />
                                                            </DataTemplate>
                                                        </ComboBox.ItemTemplate>
                                                    </ComboBox>
                                                    <!--<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding Path=Size, Mode=TwoWay}" />-->
                                                    <Slider  Margin="2" Grid.Row="1" Grid.Column="2" Minimum="1.0" Maximum="100" Value="{Binding Path=Size, Mode=TwoWay}" SmallChange="1" LargeChange="3" />
                                                    <CheckBox Grid.Row="1" Grid.Column="1" Content="Gras" IsChecked="{Binding Path=IsBold, Mode=TwoWay}" Margin="2"/>
                                                    <CheckBox Grid.Row="1" Content="Italique" IsChecked="{Binding Path=IsItalic, Mode=TwoWay}"  Margin="2"/>
                                                    <TextBlock Text="Format" Grid.Row="2" Grid.ColumnSpan="2"  Margin="2"/>
                                                    <TextBox Grid.Row="2" Grid.Column="2" Text="{Binding Path=Format, Mode=TwoWay}"  Margin="2"/>
                                                </Grid>
                                            </DataTemplate>

                                            <DataTemplate DataType="{x:Type local:VMEditableProperty}">
                                                <Button RenderTransformOrigin="0.5 0.5" Content="Cliquez ici pour éditer les  propriétés" Click="EditPropertyButton_Click" >
                                                    <Button.Template>
                                                        <ControlTemplate TargetType="Button">
                                                            <Border  BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="5" BorderThickness="{TemplateBinding BorderThickness}">
                                                                <ContentPresenter ContentSource="Content" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                            </Border>
                                                            <ControlTemplate.Triggers>
                                                                <Trigger Property="IsMouseOver" Value="true">
                                                                    <Setter Property="BorderThickness" Value="3" />
                                                                    <Setter Property="BorderBrush" Value="Black" />
                                                                </Trigger>
                                                                <Trigger Property="IsPressed" Value="true">
                                                                    <Setter Property="RenderTransform">
                                                                        <Setter.Value>
                                                                            <ScaleTransform ScaleX="0.9" ScaleY="0.9" />
                                                                        </Setter.Value>
                                                                    </Setter>
                                                                </Trigger>
                                                            </ControlTemplate.Triggers>
                                                        </ControlTemplate>
                                                    </Button.Template>
                                                </Button>
                                            </DataTemplate>

                                            <DataTemplate x:Key="collection">
                                                <ListBox HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0" ItemsSource="{Binding Value, Mode=OneWay}">
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <Button RenderTransformOrigin="0.5 0.5" Content="Cliquez ici pour éditer les  propriétés" Click="EditPropertyButton_Click">
                                                                <Button.Template>
                                                                    <ControlTemplate TargetType="Button">
                                                                        <Border  BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="5" BorderThickness="{TemplateBinding BorderThickness}" Padding="5">
                                                                            <ContentPresenter ContentSource="Content" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                                        </Border>
                                                                        <ControlTemplate.Triggers>
                                                                            <Trigger Property="IsMouseOver" Value="true">
                                                                                <Setter Property="BorderThickness" Value="3" />
                                                                                <Setter Property="BorderBrush" Value="Black" />
                                                                            </Trigger>
                                                                            <Trigger Property="IsPressed" Value="true">
                                                                                <Setter Property="RenderTransform">
                                                                                    <Setter.Value>
                                                                                        <ScaleTransform ScaleX="0.9" ScaleY="0.9" />
                                                                                    </Setter.Value>
                                                                                </Setter>
                                                                            </Trigger>
                                                                        </ControlTemplate.Triggers>
                                                                    </ControlTemplate>
                                                                </Button.Template>
                                                            </Button>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox>
                                            </DataTemplate>
                                            <DataTemplate x:Key="datasource">
                                                <StackPanel >
                                                    <ComboBox Name="provCbx" ItemsSource="{Binding Source={x:Static local:DataProviderService.DataSources}}" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True"  />
                                                    <ComboBox ItemsSource="{Binding ElementName=provCbx, Path=SelectedItem.Sources}" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True"  >
                                                        <ComboBox.SelectedItem>
                                                            <Binding Path="Value" Mode="TwoWay" />
                                                        </ComboBox.SelectedItem>
                                                    </ComboBox>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ContentControl.Resources>
                                        <ContentControl.ContentTemplateSelector>
                                            <selectors:PropertyEditorTemplateSelector />
                                        </ContentControl.ContentTemplateSelector>
                                    </ContentControl>
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>
        <Grid Grid.ColumnSpan="3" >
            <Grid.Background>
                <LinearGradientBrush EndPoint="0,1" StartPoint="1,0">
                    <GradientStop Color="#FFE1AFFF"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Grid.Background>
            <ListBox Name="hierarchyLst" Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"  FontWeight="Bold" FontSize="14" FontStyle="Italic" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="true" >
                                <Setter Property="Background" Value="Black" />
                                <Setter Property="Foreground" Value="White" />
                            </Trigger>
                        </Style.Triggers>

                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
        </Grid>
    </Grid>
</UserControl>